#conding =utf-8
from opcode import opname
import os
import json

class read_write_json():
    def open_json(self,file_path):
        file_object=os.path.dirname(__file__)+file_path
        with open(file_object,"r") as f:
            json_object=json.load(f)
            # 加载文件作为一个对象
        return json_object
        
    def read_json(self,json_key):
        json_value=self.open_json()[json_key]
        return json_value
        # pass
    
    def write_json(self,key,write_data):
        data=self.open_json("\\test_data.json")
        # 获取到json数据
        data[key]=write_data
        # 对json中某一个特定的key进行传值
        file_path=os.path.dirname(__file__) + "\\test_data.json"
        with open(file_path,"w") as f: #此处注意加"w"写入参数不然报错.
            f.write(json.dumps(data))
        # 将传值以后的json数据转化为字符串
        #然后再次写入到原来的文件中

rwj=read_write_json()
data1="aaaaaaaaddaaaaaaaaaaa"
rwj.write_json("api3/beta4",data1)
